package com.feihong.yw189.http;

import android.text.TextUtils;

import com.feihong.yw189.app.App;
import com.feihong.yw189.bluetooth.utils.util.ConstantsValue;
import com.feihong.yw189.bluetooth.utils.util.MD5Util;
import com.feihong.yw189.bluetooth.utils.util.PrefUtils;
import com.feihong.yw189.utils.UserLoginInfo;
import com.feihong.zhiwenlibrary.dialog.DJLM_PasswordDialog;

public class ZhiWenTools {

    public static boolean isSupportZhiWenPay(DJLM_PasswordDialog dialog) {

        if (dialog != null && !dialog.isFingerprintEnable()) {
            return false;
        }
        if (PrefUtils.getBoolean(App.getApp().getApplication(), ConstantsValue.ZHIWEN_STATE, false)
                && !TextUtils.isEmpty(PrefUtils.getString(App.getApp().getApplication(), ConstantsValue.ZHIWEN_KEY, ""))) {
            return true;
        }
        return false;
    }

    public static String getZhiWebKey() {
        return PrefUtils.getString(App.getApp().getApplication(), ConstantsValue.ZHIWEN_KEY, "");
    }

    public static String getRandNum() {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 10; i++) {
            sb.append("" + (int) (10 * (Math.random())));
        }
        return sb.toString();
    }

    /***
     * 获取指纹支付的密钥
     * @param randNum
     * @return
     */
    public static String getZhiWenPwd(String randNum) {
        try {
            String token = UserLoginInfo.getUserLoginInfoInstance().getUserToken();
            return randNum + MD5Util.MD5("DJLM_TOUCH_PAY" + randNum + token + getZhiWebKey()).toLowerCase();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

}
